//
//  AppDelegate.m
//  MY Project For Sport
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "TeamController.h"
#import "ColumnController.h"
#import "NewsController.h"
#import "NewsController.h"
#import <DKNightVersion.h>
#import "DataBaseHandle.h"
#import "FirstScroller.h"
#import "LeftSortsViewController.h"
#import "UIColor+Wonderful.h"

#import <UMSocial.h>
#import <UMSocialSinaSSOHandler.h>
#import <UMSocialQQHandler.h>


@interface AppDelegate ()
@property (nonatomic, retain)UITabBarController *tab;
@property (nonatomic, retain)NSMutableArray *array;
@property (nonatomic, retain)UIScrollView *scroller;
@end

@implementation AppDelegate
- (void)dealloc {

    [_window release];
    [_array release];
    [_scroller release];
    [_navi release];
    [_LeftSlideVC release];
    [_tab release];
    [super dealloc];

}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    BOOL result = [UMSocialSnsService handleOpenURL:url];
    if (result == FALSE) {
        //调用其他SDK，例如支付宝SDK等
    }
    return result;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    
     [NSThread sleepForTimeInterval:1.5];
    
    [UMSocialData setAppKey:@"56dd61bee0f55a6761002932"];
    
    [UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@"4000978177"
                                              secret:@"3fb65b8e1e5090b04410c53865d02fdb"
                                         RedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
    
    [UMSocialQQHandler setQQWithAppId:@"1105127461" appKey:@"OKC3WRpAwDkqVZMW" url:@"http://www.umeng.com/social"];
    
    
    [[DataBaseHandle shareDataBaseHandle] open];
    [[DataBaseHandle shareDataBaseHandle] createTable];
    
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
  
   
   
    // 抽屉模式
    
//    ViewController *vc  = [[ViewController alloc] init];
//    
//    self.navi = [[UINavigationController alloc] initWithRootViewController:vc];
//    LeftSortsViewController *leftVC = [[LeftSortsViewController alloc] init];
//    self.LeftSlideVC = [[LeftSlideViewController alloc] initWithLeftView:leftVC andMainView:self.navi];
//    self.window.rootViewController = self.LeftSlideVC;
//
    
      [self createTabBarController];
      [self.window makeKeyAndVisible];
    
   // NSLog(@"%@", NSHomeDirectory());
    
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]) {
        
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        
    }
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"] == YES) {
        
        FirstScroller *first = [[FirstScroller alloc] initWithFrame:self.window.frame];
        first.tag = 100;
       // first.backgroundColor = [UIColor redColor];
        [first.buttton addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.window addSubview:first];
        [first release];
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
        
    }
    
    [_window release];
    return YES;
}


- (void)nextAction:(UIButton *) button {

    
    FirstScroller *first = [self.window viewWithTag:100];
//    NSLog(@"ddd");
    [first removeFromSuperview];
    
    
}

#pragma mark - 创建 tabBarController

- (void)createTabBarController {

    //创建 tabBarController 对象
     self.tab = [[UITabBarController alloc] init];
    [_tab release];
    self.tab.tabBar.dk_barTintColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor lightGrayColor]);
    self.tab.tabBar.tintColor = [UIColor deepSkyBlue];
    [self createViewControlers];

    self.window.rootViewController = self.tab;

}

#pragma mark - 创建 viewControllers

- (void)createViewControlers {

    ViewController *vc  = [[ViewController alloc] init];
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc];
    [vc release];
    navi.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"比赛" image:[UIImage imageNamed:@"iconfont-bisai01"] tag:100];

    
    NewsController *news = [[NewsController alloc] init];
    UINavigationController *newsControll = [[UINavigationController alloc] initWithRootViewController:news];
    [news release];
    newsControll.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"新闻" image:[UIImage imageNamed:@"iconfont-xinwen"] tag:200];

    
    ColumnController *columnView = [[ColumnController alloc] init];
    UINavigationController *column = [[UINavigationController alloc] initWithRootViewController:columnView];
    [columnView release];
    column.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"专栏" image:[UIImage imageNamed:@"iconfont-zhuanlan"] tag:300];
    
    TeamController *teamView = [[TeamController alloc] init];
    UINavigationController *team = [[UINavigationController alloc] initWithRootViewController:teamView];
    [teamView release];
    team.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"球队`" image:[UIImage imageNamed:@"iconfont-anquanzhongxin"] tag:400];
    
    self.tab.viewControllers = @[navi, newsControll, column, team];
    
    [navi release];
    [newsControll release];
    [column release];
    [team release];
    

}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
